﻿using MediatR;
using SlaughterItem.Common.Domains.Check_Ins;
using SlaughterItem.Common.Dtos;
using SlaughterItem.Common.Infrastructures.Interfaces;
using SlaughterItem.Enum;

namespace GetSlaughterItem.API.Application.Commands.Week02.Check_In
{
    /// <summary>
    /// 绑定结算类型的下拉框
    /// </summary>
    public class SettlementTypeShowHandler : IRequestHandler<SettlementTypeShowCommand, Result>
    {
        IBaseRepositoryGet<SettlementType> SettlementTypeRep;

        public SettlementTypeShowHandler(IBaseRepositoryGet<SettlementType> settlementTypeRep)
        {
            SettlementTypeRep = settlementTypeRep;
        }

        public async Task<Result> Handle(SettlementTypeShowCommand request, CancellationToken cancellationToken)
        {
            var result = new Result() { Code = (int)CommonErrorCode.Search };
            try
            {
                var list = SettlementTypeRep.GetAll();
                if (list != null)
                {
                    result.Code = (int)CommonErrorCode.Success;
                    result.Data = list.ToList();
                    result.Msg = "查询成功";
                }
            }
            catch (Exception)
            {

                throw;
            }
            return result;
        }
    }
}
